﻿using UnityEngine;
using System.Collections;

public class SightUI : GameUI
{
    private float m_fAimAngleLimit = 0.0f;
    [HideInInspector] public bool m_bAimEnable = false;

    [HideInInspector] public float m_fSpeed = 10.0f;
    [HideInInspector] public float m_fStartAngle = 34.0f;

    [HideInInspector]
    public bool m_bFired = false;
    private float m_fFiredTime = 0.0f;

    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (m_bAimEnable == false)
        {
            transform.GetChild(0).transform.localRotation = Calculate.RotToAngle(m_fStartAngle);
            transform.GetChild(1).transform.localRotation = Calculate.RotToAngle(-m_fStartAngle);

        }
        else
        {
            m_fAimAngleLimit = 2.0f * (10 - transform.parent.GetComponent<UnitStatus>().m_unitData.iAccur);

            //m_fAimAngleLimit = 5.0f;

            if (m_bFired == true)
            {
                //Act
                transform.GetChild(0).localRotation = Calculate.RotToAngle(transform.GetChild(0).localEulerAngles.z + (50.0f * Time.deltaTime));
                transform.GetChild(1).localRotation = Calculate.RotToAngle(transform.GetChild(1).localEulerAngles.z - (50.0f * Time.deltaTime));

                m_fFiredTime += Time.deltaTime;

                if (m_fFiredTime > 0.1f)
                {
                    m_bFired = false;
                    m_fFiredTime = 0.0f;
                }
            }
            else
            {
                if (transform.GetChild(0).localEulerAngles.z > m_fAimAngleLimit)
                {
                    transform.GetChild(0).localRotation = Calculate.RotToAngle(transform.GetChild(0).localEulerAngles.z - (m_fSpeed));
                    transform.GetChild(1).localRotation = Calculate.RotToAngle(transform.GetChild(1).localEulerAngles.z + (m_fSpeed));
                }
            }
        }

    }
}
